<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;

class ImageController extends Controller
{
    /**
     * @return void 图片上传
     */
    public function upload(Request $request)
    {
        $request->validate([
            'file' => 'required|file|mimes:jpg,png,jpeg,gif,bmp|max:20480', // 最大允许上传XXKB
        ]);
        $path = $request->file('file')->store('avatars', 'public');
        $data = [
            'code' => 200,
            'message' => '',
            'data' => [
                'fileName' => $path,
                'id' => $path,
                'src' => Storage::url($path),
            ]
        ];
        return response()->json($data);
    }
}
